﻿namespace OboutInc.EasyMenu_Pro
{
    using System;

    public class MenuItemData
    {
        private string _dataIdField;
        private string _dataParent;
        private string _dataText;
        private string _dataUrl;
        private string _dataUrlTarget;

        public MenuItemData()
        {
            this._dataText = string.Empty;
            this._dataUrl = string.Empty;
            this._dataUrlTarget = string.Empty;
            this._dataParent = string.Empty;
            this._dataIdField = string.Empty;
        }

        public MenuItemData(string id, string innerText, string url, string parentId, string urlTarget) : this()
        {
            this.DataIdField = id;
            this.DataTextField = innerText;
            this.DataUrlField = url;
            this.DataParentIdField = parentId;
            this.DataUrlTargetField = urlTarget;
        }

        public EasyMenusCollection CreatSubMenuFromDB(MenuItemCollectionData menuItemList, MenuDataItemProperties subMenuProperty)
        {
            MenuItemCollectionData data = menuItemList;
            int num = 0;
            EasyMenusCollection menuss = new EasyMenusCollection();
            while (menuItemList.Count > 0)
            {
                MenuItemData data2 = data[0];
                string dataParentIdField = data2.DataParentIdField;
                EasyMenu easyMenu = new EasyMenu {
                    ID = "ob_em_" + dataParentIdField,
                    ShowEvent = subMenuProperty.ShowEvent,
                    AttachTo = "ob_emItem_" + dataParentIdField,
                    StyleFolder = subMenuProperty.StyleFolder,
                    Width = subMenuProperty.Width,
                    Align = subMenuProperty.Align,
                    ZIndex = subMenuProperty.ZIndex,
                    OffsetHorizontal = subMenuProperty.OffsetHorizontal,
                    OffsetVertical = subMenuProperty.OffsetVertical,
                    UseIcons = subMenuProperty.UseIcons,
                    IconsPosition = subMenuProperty.IconsPosition,
                    Position = subMenuProperty.Position,
                    DropdownIncrement = subMenuProperty.DropdownIncrement,
                    DropInterval = subMenuProperty.DropInterval,
                    KeepOpen = subMenuProperty.KeepOpen,
                    RepeatColumns = subMenuProperty.RepeatColumns
                };
                easyMenu.AddMenuItem("ob_emItem_" + data2.DataIdField, data2.DataTextField, string.Empty, data2.DataUrlField, data2.DataUrlTargetField, string.Empty);
                data.Remove(menuItemList[0]);
                for (num = 0; num < data.Count; num++)
                {
                    if (dataParentIdField == menuItemList[num].DataParentIdField)
                    {
                        easyMenu.AddMenuItem("ob_emItem_" + data[num].DataIdField, data[num].DataTextField, string.Empty, data[num].DataUrlField, data[num].DataUrlTargetField, string.Empty);
                        data.Remove(menuItemList[num]);
                        num--;
                    }
                }
                menuss.Add(easyMenu);
            }
            return menuss;
        }

        public string DataIdField
        {
            get
            {
                return this._dataIdField;
            }
            set
            {
                this._dataIdField = value;
            }
        }

        public string DataParentIdField
        {
            get
            {
                return this._dataParent;
            }
            set
            {
                this._dataParent = value;
            }
        }

        public string DataTextField
        {
            get
            {
                return this._dataText;
            }
            set
            {
                this._dataText = value;
            }
        }

        public string DataUrlField
        {
            get
            {
                return this._dataUrl;
            }
            set
            {
                this._dataUrl = value;
            }
        }

        public string DataUrlTargetField
        {
            get
            {
                return this._dataUrlTarget;
            }
            set
            {
                this._dataUrlTarget = value;
            }
        }
    }
}

